package com.sleepcamel.resteasyConfigurator.components.tree.strategies;

import com.sleepcamel.rest.domain.BaseMethod;
import com.sleepcamel.rest.domain.Mapping;
import com.sleepcamel.rest.domain.Project;
import com.sleepcamel.rest.domain.method.RESTMethod;
import com.sleepcamel.resteasyConfigurator.components.tree.ITreeLabelStrategy;

public class PublishTreeLabelStrategy implements ITreeLabelStrategy {

	@Override
	public boolean isLabelProperty(Object arg0, String arg1) {
		if (arg0 instanceof Project	&& (arg1.equals("name") || arg1.equals("childs")))
			return true;

		if (arg0 instanceof Mapping	&& (arg1.equals("name") || arg1.equals("path")))
			return true;

		if (arg0 instanceof BaseMethod	&& (arg1.equals("name") || arg1.equals("path") || arg1.equals("type")))
			return true;

		return false;
	}

	@Override
	public String getText(Object arg0) {
		if (arg0 instanceof Project) {
			return ((Project) arg0).getName();
		}
		if (arg0 instanceof Mapping) {
			Mapping mapping = (Mapping) arg0;
			return mapping.getPath().getValue();
		}
		if (arg0 instanceof BaseMethod) {
			BaseMethod<?> method = ((BaseMethod<?>) arg0);
			StringBuilder sb = new StringBuilder();
			if (method instanceof RESTMethod)
				sb.append(((RESTMethod) method).getPath().getValue()).append(
						" - ");
			sb.append(method.getName());
			return sb.toString();
		}
		return "No name";
	}
}